package week5th;

public class Product implements Comparable<Product> {

    protected String name;
    protected int price;
    protected int discount;

    public Product() {
        this.name = "";
        this.price = 0;
        this.discount = 10;
    }

    public Product(String name, int price) {
        this.name = name;
        this.price = price;
        this.discount = 10;
    }

    public Product(String name, int price, int discount) {
        this.name = name;
        this.price = price;
        this.discount = discount;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getDiscount() {
        return discount;
    }

    public void setDiscount(int discount) {
        this.discount = discount;
    }

    @Override
    public int compareTo(Product o) {
        if (name.compareTo(o.name) < 0)
            return -1;
        else if (name.compareTo(o.name) > 0)
            return 1;
        else
            if (price < o.price) {
            return -1;
            }
            else if (price > o.price) {
            return 1;
            }
        return 0;
    }

    @Override
    public String toString() {
        if (discount != 10)
            return "名称：" + name + "\t" + "价格：" + price + "\t" + "折扣：" + discount;
        return "名称：" + name + "\t" + "价格：" + price;
    }
}
